package com.dw.etl.core.controller;

import com.dw.etl.common.base.BaseException;
import com.dw.etl.common.base.BaseResult;
import com.dw.etl.common.constant.CommonResultConstant;
import com.dw.etl.common.vo.PaginationVO;
import com.dw.etl.core.api.BaseSdItemService;
import com.dw.etl.core.bean.model.BaseSdItem;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;

/**
 * baseSdItem控制器
 * Created by hozeData on 2021/05/21.
 */
@RestController
@RequestMapping("/etl/baseSdItem/")
@Api( tags="基础字典项")
public class BaseSdItemController {

    @Autowired
    BaseSdItemService baseSdItemService;

    @ApiOperation(value="分页查询")
    @RequestMapping(value="findByPage", method=RequestMethod.POST)
    public BaseResult findByPage(@RequestBody BaseSdItem baseSdItem, Integer pageNum, Integer pageSize) {
        PaginationVO<BaseSdItem> pageVO = baseSdItemService.findPageByModel(baseSdItem, pageNum, pageSize);
        return new BaseResult(CommonResultConstant.SUCCESS, pageVO);
    }

    @ApiOperation(value="保存")
    @ApiImplicitParam(name="baseSdItem", value="实体", paramType="body", required=true, dataType="BaseSdItem")
    @RequestMapping(value="insert", method=RequestMethod.POST)
    public BaseResult insert(@RequestBody BaseSdItem baseSdItem, HttpServletRequest request)  {
        int num = baseSdItemService.insertSelective(baseSdItem);
        return new BaseResult(CommonResultConstant.SUCCESS, num);
    }

    @ApiOperation(value="详情")
    @ApiImplicitParam(name="idSdItem", value="主键", paramType="query", required=true, dataType="Long")
    @RequestMapping(value="getById", method=RequestMethod.GET)
    public BaseResult getById(Long idSdItem, HttpServletRequest request) throws BaseException {
        BaseSdItem baseSdItem = baseSdItemService.getById(idSdItem);
        return new BaseResult(CommonResultConstant.SUCCESS, baseSdItem);
    }

    @ApiOperation(value="修改")
    @ApiImplicitParam(name="baseSdItem", value="实体", paramType="body", required=true, dataType="BaseSdItem")
    @RequestMapping(value="update", method=RequestMethod.POST)
    public BaseResult update(@RequestBody BaseSdItem baseSdItem, HttpServletRequest request)  {
        int num = baseSdItemService.updateByIdSelective(baseSdItem);
        return new BaseResult(CommonResultConstant.SUCCESS, num);
    }

    @ApiOperation(value="根据主键删除")
    @ApiImplicitParam(name="idSdItem", value="主键", paramType="query", required=true, dataType="Long")
    @RequestMapping(value="delete", method=RequestMethod.GET)
    public BaseResult delete(Long idSdItem, HttpServletRequest request) throws BaseException {
        int num = baseSdItemService.deleteById(idSdItem);
        return new BaseResult(CommonResultConstant.SUCCESS, num);
    }



}
